<?php
/*
* 20180328 dsl
* 筛选已归还订单，可查到快递单号信息则修改状态为待结算
*/
namespace app\merchant\controller;

use think\Controller;
use think\Db;
use app\common\tool\BSP;

class Timeclean extends Controller
{
    public function index()
    {
        $borrow_list = Db::query('SELECT * FROM (SELECT bo.id, bo.order_sn, zeo.express_order_id, zeo.express_no, zeo.id as zid FROM `zj_book_order` bo LEFT JOIN zj_express_order zeo ON bo.id=zeo.book_order_id where bo.status = 4 and zeo.express_no != "" ORDER BY zeo.id desc)gg GROUP BY gg.order_sn ORDER BY gg.id');

        $bsp = new BSP();
        $flag = 0;
        foreach ($borrow_list as $key => $va) {
        	$data = $bsp->orderRoute($va['express_no']);
        	
        	//更新状态：5-待结算
        	$up_data = array();
        	if ($data['status']!=0) {
        		$up_data['status'] = 5;
        		$up_data['update_time'] = time();
        		$res = Db("zj_book_order")->where("id" ,$va['id'])->update($up_data);

        		$flag ++;
        	}
        }
        return $flag;
    }


}
